#include<stdio.h>//循环单链表
#include<stdlib.h>
#include<string.h>
typedef struct node{
    int data;
    struct node* next;
}Node;
Node* Createlist();
void Showlist(Node* head);
void delectlist(Node* head,int data);
void headinsert(Node* head,int data);
void tailinsert(Node* head,int data);
void Clearlist(Node* head);
int isempty(Node* head);
int main(){
    Node* head=Createlist();
    headinsert(head,1);
    headinsert(head,2);
    headinsert(head,3);
    headinsert(head,4);
    headinsert(head,5);
    tailinsert(head,19);
    headinsert(head,23);
    printf("删除前\n");
    Showlist(head);
   printf("请输入你要删除的元素:\n");
   int data;
   scanf("%d",&data);
   delectlist(head,data);
    printf("删除后:\n");
    Showlist(head);
    return 0;
}
Node* Createlist(){
    Node* head=(Node*)malloc(sizeof(Node));
    head->data=0;
    head->next=head;
}
int isempty(Node* head){
    if(head->data==0){
        return 1;
    }
    return 0;
}
void headinsert(Node* head, int data){
        Node* pnew=(Node*)malloc(sizeof(Node));
        pnew->data=data;
        pnew->next=head->next;
        head->next=pnew;
        head->data++;
}
void tailinsert(Node* head,int data){
    Node* pstr=head;
    while(pstr->next!=head){
        pstr=pstr->next;
    }
    Node* pnew=(Node*)malloc(sizeof(Node));
    pnew->data=data;
    pstr->next=pnew;
    pnew->next=head;
    head->data++;
}
void delectlist(Node* head,int data){
        if(isempty(head)==1){
            printf("链表为空，删除失败");
        }
        else {
            Node* pstr=head->next;
            int Flags=0;
            for(;pstr->next!=head;pstr=pstr->next){
                if(pstr->next->data==data){
                    Node* temp;
                    temp=pstr->next;
                    pstr->next=temp->next;
                    Flags=1;
                    head->data--;
                    break;
                }
                if(Flags==0){
                    printf("没有这个元素,删除失败");
                }
               
                }
            }
        
        }
void Clearlist(Node* head){
    if(isempty(head)){
        printf("链表为空，删除失败");
    }
    else{
        head->data=0;
        head->next=head;
    }
}
void Showlist(Node* head){
    Node* pstr=head->next;
    printf("链表中有%d个元素:",head->data);
    for(;pstr!=head;pstr=pstr->next){
        printf(pstr==head->next?"%d":"->%d",pstr->data);
    }

}




